/**
 * ReportGear(2011)
 */
package net.abbp.report.view.grid;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import javax.swing.JComponent;
import javax.swing.UIManager;

import net.abbp.report.model.ReportModel;
import net.abbp.report.view.GridView;

/**
 * 构成GridView的组件基类
 * 
 * @version 1.0 2011-3-14
 * @author <a herf="lexloo@gmail.com">lexloo</a>
 * @since Report 1.0
 */
public class BaseGridComponent extends JComponent implements PropertyChangeListener {
    private static final long serialVersionUID = 8438590482726420852L;
    /**
     * 表格视图
     */
    protected GridView gridView;
    /**
     * 报表模型
     */
    protected ReportModel reportModel;

    /**
     * 构造器
     * 
     * @param worksheet
     *            工作簿
     */
    public BaseGridComponent(GridView gridView) {
        this.gridView = gridView;
        this.reportModel = this.gridView.getReportModel();

        this.setBackground(UIManager.getColor("panel.background"));
    }

    @Override
    public void propertyChange(PropertyChangeEvent evt) {
        if (evt.getPropertyName() == GridView.PROPERTY_MODEL) {
            this.reportModel = (ReportModel) evt.getNewValue();
        }
    }

    /**
     * 获取报表视图
     * 
     * @return 表格视图
     */
    public final GridView getGridView() {
        return this.gridView;
    }

    /**
     * 获取报表模型
     * 
     * @return 报表模型
     */
    public final ReportModel getReportModel() {
        return this.reportModel;
    }
}